<?php

namespace app\common\model\factory;

use think\Model;


class Category extends Model
{





    // 表名
    protected $name = 'factory_category';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text',
        'image_str',
        'type_text'

    ];



    public function getStatusList()
    {
        return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
    }

    public function getImageStrAttr($value, $data)
    {
        return isset($data['image']) && $data['image'] ? cdnurl($data['image'], true) : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }





    public function getTypeList()
    {
        return ['normal' => __('Type normal'), 'service' => __('Type service')];
    }




    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }



    public function admin()
    {
        return $this->belongsTo('app\common\model\Admin', 'admin_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
